package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "菜品接口")
@Slf4j
@RequestMapping("/admin/dish")
public class DishController {


    @Autowired
    private DishService dishServiced;

    /**
     * 新增菜品和对应的口味
     *
     * @param dishDTO
     * @return
     */
    @ApiOperation("新增菜品")
    @PostMapping
    public Result addDish(@RequestBody DishDTO dishDTO) {
        log.info("新增菜品—>{}", dishDTO);
        dishServiced.add(dishDTO);
        return Result.success();
    }

    /**
     * 菜品分页查询
     *
     * @param dishPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("查询菜品信息")
    public Result<PageResult> search(DishPageQueryDTO dishPageQueryDTO) {
        log.info("菜品分页查询信息->{}", dishPageQueryDTO);
        PageResult pageResult = dishServiced.search(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 批量删除菜品
     *
     * @return
     */
    @DeleteMapping
    @ApiOperation("批量删除菜品")
    public Result deleteById(@RequestParam List<Long> ids) {
        log.info("批量删除菜品ids->{}", ids);
        dishServiced.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 菜品起售、停售
     *
     * @param status
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("菜品起售、停售")
    public Result updateSalesStatus(@PathVariable Integer status, Long id) {
        log.info("菜品起售、停售{} {}", status, id);
        dishServiced.updateSalesStatus(status, id);
        return Result.success();
    }

    /**
     * 根据分类id查询菜品
     *
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据分类id查询菜品")
    public Result<DishVO> getDishInfoById(@PathVariable Long id) {
        log.info("根据分类id查询菜品{}", id);
        DishVO dishVO = dishServiced.getInfoDish(id);
        return Result.success(dishVO);
    }

    /**
     * 修改菜品
     *
     * @param dishDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改菜品")
    public Result updateDish(@RequestBody DishDTO dishDTO) {
        log.info("修改菜品");
        dishServiced.updateDish(dishDTO);
        return Result.success();
    }


}
